import requests
"""
发起接口请求，需要的必备要素：
1、请求方式
2、IP地址
3、端口号
4、接口的地址
5、请求参数（headers参数、body参数）
"""
# 发起post请求
reponse=requests.post(url="http://115.29.179.199:8899/adminapi/login",json={"account":"admin","pwd":"123456","key":"682703980f3a2","captchaType":"blockPuzzle","captchaVerification":""})
# 打印响应结果应为json格式
# print(reponse.json()) #结果是python的原始对象，字典
# 打印响应的url
# print(reponse.url)  #请求的地址：http://115.29.179.199:8899/adminapi/login
# 打印响应的文本
# print(reponse.text)  #返回的是字符串

# 打印响应的二进制
# print(reponse.content)
#打印响应状态码
# print(reponse.status_code) #200
# 打印响应headers
# print(reponse.headers)
#获取cookie
# print(reponse.cookies)
# 获取响应时间
# print(reponse.elapsed.microseconds)
# 获取响应头字符编码
# print(reponse.encoding)  #utf-8

# 发送get请求 eg:用户分组举例  下面网址 就是 用户的查询接口
# 方式一
# reponse=requests.get(url="http://115.29.179.199:8899/adminapi/user/user_group/list?page=1&limit=15",headers={"authori-zation":"Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJwd2QiOiI3MWE0OTBlZmJiNTg4NjQyYjNmNmYyODhlNzEzNDU1ZSIsImlzcyI6IjExNS4yOS4xNzkuMTk5Ojg4OTkiLCJhdWQiOiIxMTUuMjkuMTc5LjE5OTo4ODk5IiwiaWF0IjoxNzQ3Mzg3MzAyLCJuYmYiOjE3NDczODczMDIsImV4cCI6MTc0OTk3OTMwMiwianRpIjp7ImlkIjoxLCJ0eXBlIjoiYWRtaW4ifX0.dnu1nY7vAcEnH3ypMhZyz5nzBTrx2xqanZUhnRarqkQ"})
# 方式二 目前不对
# response = requests.get(url="http://115.29.179.199:8899/adminapi/user/user_group/list",headers={"authori-zation":"Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJwd2QiOiI3MWE0OTBlZmJiNTg4NjQyYjNmNmYyODhlNzEzNDU1ZSIsImlzcyI6IjExNS4yOS4xNzkuMTk5Ojg4OTkiLCJhdWQiOiIxMTUuMjkuMTc5LjE5OTo4ODk5IiwiaWF0IjoxNzQ3Mzg3MzAyLCJuYmYiOjE3NDczODczMDIsImV4cCI6MTc0OTk3OTMwMiwianRpIjp7ImlkIjoxLCJ0eXBlIjoiYWRtaW4ifX0.dnu1nY7vAcEnH3ypMhZyz5nzBTrx2xqanZUhnRarqkQ"},params={"page":1,"limit":15})
# 打印响应结果
# print(reponse.json())

# 通过requests上传图片
url="https://graph.baidu.com/upload"  #百度上传接口
files={
    "image":('屏幕截图',open(r'D:\Users\Administrator\Desktop\屏幕截图.jpg','rb'),"image/jpeg")
}
r = requests.post(url,files=files)
print(r.json())
